<?php
session_start();

if (!isset($_SESSION['students']))
{
	$_SESSION['students'] = array(
		"1" => array("name" => "Mary", "class_id" => "1"),
		"2" => array("name" => "John", "class_id" => "1"),
		"3" => array("name" => "Jane", "class_id" => "2"),
		"4" => array("name" => "Luke", "class_id" => "2"),
	);
}
$students = &$_SESSION['students'];

$class_id = $_REQUEST['class_id'];

$output = array();
foreach ($students as $id => $row)
{
	if ($row["class_id"] == $class_id)
	{
		$output[] = array( "id" => $id, "name" => $row["name"] );
	}
}
echo json_encode($output);
?>